<?php

/**
* create by hx
* time 2011 12 1 17:00
**/
class AndroidController extends Controller {
	
	 public function actionIndex() {	 
	 
		$pageNum = 5;
 
		if(isset($_POST['title'])){
		
			if(isset($_POST['page'])){
			
				$page = $_POST['page'];
			
				$start = $page*$pageNum;
			
				$sql = "SELECT * FROM  `meeting_cai` WHERE  `title` LIKE  '%".$_POST['title']."%'  LIMIT ".$start." , ".$pageNum."";
		
			}else{
		
				$sql = "SELECT * FROM  `meeting_cai` WHERE  `title` LIKE  '%".$_POST['title']."%'  LIMIT 0 , 15";
		
			}		

			//$q = mysql_query($sql);
			$output = Yii::app()->db->createCommand($sql)->queryAll();
			//print_r($q);
		
			$i=0;		
			
			while(isset($output[$i])){

				$output[$i]['title'] = urlencode($output[$i]['title']);
				$output[$i]['content'] = urlencode($this->delBlock(strip_tags($this->utf8Substr($output[$i]['content'],0,100))));
				$output[$i]['province'] = urlencode($this->delBlock($output[$i]['province']));
				$output[$i]['city'] = urlencode($this->delBlock($output[$i]['city']));
				$output[$i]['area'] = urlencode($output[$i]['area']);
				$output[$i]['country'] = urlencode($this->delBlock($output[$i]['country']));
				$output[$i]['subject'] = urlencode($output[$i]['subject']);
				$output[$i]['host'] = urlencode($output[$i]['host']);
				$output[$i]['contact_name'] = urlencode($output[$i]['contact_name']);
				$output[$i]['website'] = urlencode($output[$i]['website']);
				$output[$i]['contact_email'] = urlencode($output[$i]['contact_email']);
				$output[$i]['contact_tel'] = urlencode($output[$i]['contact_tel']);
				$output[$i]['start_time'] = date("Y-m-d",($output[$i]['start_time']));
				$output[$i]['end_time'] = date("Y-m-d",($output[$i]['end_time']));
				
				$i++;
         
			} 	
			print(urldecode(json_encode($output))); 

  
		}
    }
	
	

	//截取utf8字符串

	public function utf8Substr($str, $from, $len){

		return preg_replace('#^(?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,'.$from.'}'.

                       '((?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,'.$len.'}).*#s',

                       '$1',$str);

	}
	
	public function delBlock($str){
	
		// 首先去掉头尾空格
		$str = trim($str);

		// 接着去掉两个空格以上的
		$str = preg_replace('/\s(?=\s)/', '', $str);
		
		$str=preg_replace('/\s+/', ' ', $str); //过滤多余回车
		
		$str = preg_replace('/[\n\r\t]/', ' ', $str);
		
		return $str;

	
	}
}